package com.haiyou.dc.thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TdDownload extends Thread {

    private String name;
    private String url;

    public TdDownload(String name, String url) {
        this.name = name;
        this.url = url;
    }

    @Override
    public void run() {
        try {
            System.out.println("---------------->" + name);
            FileUtils.copyURLToFile(new URL(url), new File(name));
        } catch (IOException e) {
            System.out.println("下载失败");
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new TdDownload("aa.jpg", "http://a2.att.hudong.com/08/72/01300000165476121273722687045.jpg").start();
        new TdDownload("bb.png", "http://www.togogo.net/image/zhuanti/redhat/cup3.png").start();
        new TdDownload("cc.png", "http://cms-bucket.ws.126.net/2020/0209/c0d17242p00q5f6ur0063c000nk00csc.png").start();

    }
}
